<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('开始时间')" prop="startDate">
            <el-date-picker
              v-model="form.startDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('开始时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('结束时间')" prop="endDate">
            <el-date-picker
              v-model="form.endDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('结束时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公司')" prop="jobCpy">
            <el-input v-model="form.jobCpy" :placeholder="$t('公司')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公司规模')" prop="jobCpySize">
            <el-input v-model="form.jobCpySize" :placeholder="$t('公司规模')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公司描述')" prop="jobCpyDesc">
            <el-input v-model="form.jobCpyDesc" :placeholder="$t('公司描述')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('行业')" prop="jobIndustry">
            <el-input v-model="form.jobIndustry" :placeholder="$t('行业')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('职位')" prop="jobPosition">
            <el-input v-model="form.jobPosition" :placeholder="$t('职位')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('所在部门')" prop="jobDept">
            <el-input v-model="form.jobDept" :placeholder="$t('所在部门')" show-word-limit maxlength="25" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('工作性质')" prop="jobNature">
            <el-input v-model="form.jobNature" :placeholder="$t('工作性质')" show-word-limit maxlength="25" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('工作薪资')" prop="jobSalary">
            <el-input v-model="form.jobSalary" :placeholder="$t('工作薪资')" show-word-limit maxlength="25" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('工作地点')" prop="jobLocation">
            <el-input v-model="form.jobLocation" :placeholder="$t('工作地点')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('离职原因')" prop="jobWhyLeave">
            <el-input v-model="form.jobWhyLeave" :placeholder="$t('离职原因')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('持续时间')" prop="jobDuration">
            <el-input v-model="form.jobDuration" :placeholder="$t('持续时间')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('工作能力')" prop="jobCapacity">
            <el-input v-model="form.jobCapacity" :placeholder="$t('工作能力')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('工作内容')" prop="jobContent">
            <el-input v-model="form.jobContent" type="textarea" :placeholder="$t('工作内容')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" show-word-limit :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="resume:jobExp" />
    </div>
  </div>
</template>

<script>
    import { saveResumeJobExp, getResumeJobExp } from '@/api/oa/resume/jobExp/resumeJobExp'
    export default {
        data() {
          return {
              // 表单参数
              form: {},
              // 遮罩层
              loading: false,
              // 表单校验
              rules: {
                startDate: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                endDate: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }],
                jobCpy: [{ required: true, message: this.$t('必填信息'),	trigger: 'blur' }]
              }
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data != null && data.id !== undefined) {
                    this.loading = true
                    getResumeJobExp(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    resumeId: this.$route.query.resumeId,
                    startDate: undefined,
                    endDate: undefined,
                    jobCpy: undefined,
                    jobCpySize: undefined,
                    jobCpyDesc: undefined,
                    jobIndustry: undefined,
                    jobPosition: undefined,
                    jobDept: undefined,
                    jobNature: undefined,
                    jobSalary: undefined,
                    jobLocation: undefined,
                    jobWhyLeave: undefined,
                    jobDuration: undefined,
                    jobCapacity: undefined,
                    jobContent: undefined,
                    remark: undefined,
                    createBy: undefined,
                    updateBy: undefined,
                    createTime: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveResumeJobExp(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                })
           }

        }

    }
</script>
